<?php
    $registry   = Zend_Registry::getInstance();
    $constants = $registry->constants;
    $this->headLink()->appendStylesheet($this->baseUrl().'/static/css/main.css');
    $this->headScript()->appendFile("/static/js/jquery.js");
    $this->headScript()->appendFile("/static/js/jquery-ui-1.10.3.custom.js");
    $this->headScript()->appendFile("/static/js/jquery-ui-1.10.3.custom.min.js");
    
?>
<html>
    <head>
        <?php 
            echo $this->headLink();
            echo $this->headScript();
            ?>
        <meta charset="utf-8">
        <title><?php echo $this->title;?></title>
        <link rel="shortcut icon" href="/static/images/favicon.png">
    </head>
    <body>
        <div class="wrapper">
            <div class="header">
                <div class="topbar-center">
                    <span style="color:#DF5A49;font-weight: bold">APPROVE</span>
                    <span style="color:#000">PLACE</span>
                </div>
                <div class="login-logout">
                    <span><?php echo "Xin chào ".$this->userName?></span> | <span><a href="/place/index/logout">LogOut</a></span>

                </div>
            </div>
            <div class="content">
                <div class="menu-left">
                    <ul>
                    <?php foreach($this->userFeature as $key=>$value){?>
                        <li><a href="<?php echo $value->feature_url?>"><?php echo $value->feature_name;?></a></li>
                    <?php }?>
                    </ul>
                </div>
                <div class="deal-content3">
                    <div class="content1-title" >
                        Approve Requested Place
                    </div>
                    <div class="alert-title" id="alert"></div>
                    <div class="table-alt" id="request-table">
                    </div>
                    <div class="button-add">
                        <button class="button-test" onclick="approveMultiPlace('/place/approve-place/approve')">
                            Approve Place
                        </button>
                        <button class="button-test" onclick="rejectMultiPlace('/place/approve-place/reject')">
                            Reject Place
                        </button>
                    </div>          
                </div>
            </div>
        </div>
    </body>
</html>
<script>

    $(document).ready(function() {
        $("#request-table").load('/place/approve-place/get-request-place');
    });
    
        
    function checkAll() {
        var inputs = document.getElementsByTagName("input");

        for (var i = 0; i < inputs.length; i++)
            if (inputs[i].type == "checkbox") {
                if ($('#checkAll').is(':checked'))
                    inputs[i].checked = true;
                else
                    inputs[i].checked = false;
            }
    }
    
    function approveMultiPlace(url){
        request_page = $.trim($("#pagging-seach").val());
        if ($("input[name='merchant_selected[]']").is(":checked")) {
            if (confirm("<?php echo $constants->CONFIM_MERCHANT_APPROVE;?>")) {
                var placeList = $("input[name='merchant_selected[]']:checked").map(function() {
                    return Number(this.value);
                }).get().join(",");
                $.get(url, {
                    'place_list' : placeList
                }, function(responseData) {
                    $('#alert').html(responseData);
                    request_url = "/place/approve-place/get-request-place?page="+request_page;
                    $("#request-table").load(request_url);
                });
            }
        } else {
            $("#alert").text('<?php echo $constants->CONFIM_MERCHANT_APPROVE_SELECT;?>');
        }
    }
    
    function rejectMultiPlace(url){
        request_page = $.trim($("#pagging-seach").val());
        if ($("input[name='merchant_selected[]']").is(":checked")) {
            if (confirm("<?php echo $constants->CONFIM_MERCHANT_REJECT;?>")) {
                var placeList = $("input[name='merchant_selected[]']:checked").map(function() {
                    return Number(this.value);
                }).get().join(",");
                $.get(url, {
                    'place_list' : placeList
                }, function(responseData) {
                    $('#alert').html(responseData);
                    request_url = "/place/approve-place/get-request-place?page="+request_page;
                    $("#request-table").load(request_url);
                });
            }
        } else {
            $("#alert").text('<?php echo $constants->CONFIM_MERCHANT_REJECT_SELECT;?>');
        }
    }
    
    
</script>